﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Card : MonoBehaviour
{
    /// <summary>
    /// 卡牌ID, 用于区分不同卡牌
    /// </summary>
    private int id;
    public int ID
    {
        get
        {
            return id;
        }
    }
    /// <summary>
    /// 卡牌正面图片
    /// </summary>
    private Sprite frontImg;
    /// <summary>
    /// 卡牌背面图片
    /// </summary>
    private Sprite backImg;
    /// <summary>
    /// 卡牌匹配成功后图片
    /// </summary>
    private Sprite succImg;

    /// <summary>
    /// 图片组件
    /// </summary>
    private Image showImg;

    public Button cardBtn;

    /// <summary>
    /// 初始化卡牌
    /// </summary>
    /// <param name="id"></param>
    /// <param name="frontImg"></param>
    /// <param name="backImg"></param>
    /// <param name="succImg"></param>
    public void InitCard(int id, Sprite frontImg, Sprite backImg, Sprite succImg)
    {
        this.id = id;
        this.frontImg = frontImg;
        this.backImg = backImg;
        this.succImg = succImg;

        showImg = GetComponent<Image>();
        showImg.sprite = this.backImg;

        cardBtn = GetComponent<Button>();
    }

    /// <summary>
    /// 翻牌
    /// </summary>
    public void SetCard()
    {
        if (showImg)
        {
            showImg.sprite = frontImg;
            cardBtn.interactable = false;
        }
    }

    /// <summary>
    /// 匹配成功
    /// </summary>
    public void SetSuccess()
    {
        if (showImg)
        {
            showImg.sprite = succImg;
        }
    }

    /// <summary>
    /// 恢复牌背
    /// </summary>
    public void SetRecover()
    {
        if (showImg)
        {
            showImg.sprite = backImg;
            cardBtn.interactable = true;
        }
    }
}
